<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import { getToken } from '@/utils/auth'
import curd from '@/api/curd'
export default {
  name: 'App',
  data() {
    return {
      // currentTime: new Date().toLocaleString()
      // show: sessionStorage.getItem('messageShow') ? 'true' : 'false'// 按可以进行取值
    }
  },
  created() {
    // 初次请求
    // this.fetchData();
    // 设置整点定时发送请求
    // console.log('获取成功', this.show)
    sessionStorage.setItem('messageShow', false)
    setInterval(() => {
      const now = new Date()

      var reslut = false
      if (sessionStorage.getItem('messageShow') == 'true') {
        reslut = true
      }
      console.log('获取成功,定时任务', reslut)
      if (getToken() && !reslut) {
      // this.fetchData();
        var data = {
          'filter[status]': '0',
          'filter[message]': '0'
        }
        curd('roomLeaseRecord').index(data).then(res => {
          console.log('入住申请', res)
          if (res.data.total) {
            this.$alert('您有' + res.data.total + '条入住申请待处理', '入住申请通知', {
              confirmButtonText: '确定',
              callback: action => {
                curd('roomLeaseRecord').get('saveMessage').then(res => {
                  console.log('入住申请已通知', res)
                })
                console.log('我被输出了，我是callback')
                sessionStorage.setItem('messageShow', false)
              }
            })
            sessionStorage.setItem('messageShow', true)
          }
        })
        console.log('我被触发了,我是定时任务', now.getMinutes() + '/' + now.getSeconds())
      }
      // this.currentTime = now.toLocaleString()
    }, 60000)
  }
}
</script>
